<template>
    <view>
        <Header returnIcon="white" :background="background" :title="title" />
        <CheckTitle :titleList="titleList" :checkIndex="checkIndex" :unread="unread" @checkChange="checkChange" />
        <view class="content" :style="{'min-height': `${noBarHeight - 52}px`}">
            <view v-if="checkIndex == 1" class="main">
                <view @click="messageInfo(item)" class="content_black" v-for="(item, index) in dataList" :key="index">
                    <view class="unread" v-if="item.hits == 0"></view>
                    <view  class="title">{{ item.title }}</view>
                    <view class="time">{{ item.add_time }}</view>
                </view>
            </view>
            <view v-if="checkIndex == 2" class="pro_main">
                <ProBlack
                    v-for="(item, index) in dataList"
                    :key="index"
                    :dataDetail="item"
                    unread="true"
                />
            </view>
            <view v-if="checkIndex == 3" class="main">
                <view class="content_black" v-for="(item, index) in dataList" :key="index">
                    <view class="unread" v-if="item.hits == 0"></view>
                    <view  class="title">{{ item.title }}</view>
                    <view class="time">{{ item.add_time }}</view>
                </view>
            </view>
        </view>
    </view>
</template>
<script>
import Header from "@/components/Header.vue";
import CheckTitle from "@/components/CheckTitle.vue";
import ProBlack from "@/components/ProBlock.vue";
import {articleList} from "@/utils/api/message";
import {message} from "../../../utils/api/message";
var app = getApp()
export default ({
    name: "imCenter",
    data() {
        return {
            background: 'linear-gradient(0, #5162FD, #8E4EF7)',
            title: '消息中心',
            noBarHeight: app.globalData.noBarHeight,
            dataList: [],
            checkIndex: 1,
            unread: [1, 2], // 未读红点
            titleList: [
                {
                    id: 1,
                    title: '探索新知'
                },
                {
                    id: 2,
                    title: '项目推荐'
                },
                {
                    id: 3,
                    title: '通知通告'
                }
            ],
            pages: {
                total: 0,
                size: 20,
                page: 1,
                isOver: false
            }
        }
    },
    components: {
        Header,
        CheckTitle,
        ProBlack
    },
    onLoad() {
        this.getList()
    },
    methods: {
        // 重置分页信息
        resetting() {
            this.pages = {
                total: 0,
                size: 20,
                page: 1,
                isOver: false
            }
            this.dataList = []
        },
        async getList() {
            const params = {
                uid: uni.getStorageSync('uid'),
                // searchType: 'explore',
                // keyword: ''

            }
            const pages = {
                p: this.pages.page,
                pages: this.pages.size
            }
            let data = {}
            if (this.checkIndex == 1) {
                params.cate_id = 1
                data = await articleList(params, pages)
            } else if (this.checkIndex == 2) {
                params.type = 3
                data = await message(params, pages)
            } else if (this.checkIndex == 3) {
                params.cate_id = 10
                data = await articleList(params, pages)
            }
            this.dataList = this.dataList.concat(data.data.data)
            this.pages.total = data.data.total
            if (data.data.total < (data.data.page * data.data.p)) {
                this.pages.isOver = true
            }

        },
        checkChange(e) {
            this.checkIndex = e
            this.resetting()
            this.getList()
        },
        messageInfo(e) {
            uni.navigateTo({
                url: `../messageInfo/messageInfo?id=${e.id}`
            })
        }
    }
})
</script>

<style scoped lang="scss">
.content {
    flex-direction: column;
    background: #f8f8f8;
    display: flex;
    box-sizing: border-box;
    justify-content: space-between;
    align-items: center;
    .main {
        padding-top: 12rpx;
        box-sizing: border-box;
        width: 100%;
        .content_black {
            background: white;
            width: 100%;
            height: 88rpx;
            display: flex;
            align-items: center;
            justify-content: flex-end;
            padding: 20rpx 30rpx 20rpx 20rpx;
            box-sizing: border-box;
            border-bottom: 2rpx solid #fbfbfb;
            .unread {
                width: 12rpx;
                height: 12rpx;
                border-radius: 50%;
                background: red;
                margin-right: 10rpx;
            }
            .title {
                height: 40rpx;
                font-size: 28rpx;
                font-family: PingFangSC, PingFang SC;
                font-weight: 400;
                color: #494949;
                line-height: 40rpx;
                width: 57%;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
            }
            .time {
                width: 40%;
                height: 33rpx;
                font-size: 24rpx;
                font-family: PingFangSC, PingFang SC;
                font-weight: 400;
                color: #9B9B9B;
                line-height: 33rpx;
                text-align: right;
            }
        }
    }
    .pro_main {
        width: 100%;
        padding: 12rpx 12rpx 0;
        box-sizing: border-box;
    }

}
</style>
